@extends('layouts.main')

@section('title', '大区指标进度汇总')

@section('content')
<div class="btn-group" role="group">
    <a href="{{ action('Report\IndexController@index') }}" class="btn btn-primary">返回报表列表</a>
</div>
<div class="clearfix"></div>
<hr>
<h3>@yield('title')</h3>
<a href="{{ action('Report\RegionIndicatorProgress@visual') }}" class="btn btn-primary">可视化</a>
<button id="cache" class="btn btn-primary">缓存数据</button>
<button id="export" class="btn btn-primary">导出数据</button>
<div class="clearfix"></div>
<hr>
<form class="form-inline pull-right" method="get" action="{{ action('Report\RegionIndicatorProgress@index') }}">
    
    <div class="form-group">
        <label for="year">年份</label>
        <select class="form-control" id="year" name="year">
            <option>请选择年份</option>
            @for($i = 2020; $i <= 2030; $i++)
            <option value="{{ $i }}" @if(request()->year == $i) selected @endif>{{ $i }}</option>
            @endfor
          </select>
    </div>

	<div class="form-group">
        <label for="month">月份</label>
        <select class="form-control" id="month" name="month">
            <option>请选择月份</option>
            @for($i = 1; $i <= 12; $i++)
            <option value="{{ $i }}" @if(request()->month == $i) selected @endif>{{ $i }}</option>
            @endfor
          </select>
    </div>

    <button type="submit" name="search" value="search" class="btn btn-primary">查询</button>

</form>

<div class="clearfix"></div>
<hr>

@include('report.region_indicator_progress.table')

<script>
	$(document).ready(function(){
		//批量更新
		$('#cache').click(function(){
            //选择范围
            var year = $('#year').val();
            var month = $('#month').val();
			if(!$.isNumeric(year) || !$.isNumeric(month)){
				alert("请选择需要缓存数据的年份和月份！");
				return;
			}
            $.post("/report/region_indicator_progress/cache", {
                '_token': '{{ csrf_token() }}',
                'year': year,
                'month': month,
            }, function(data){
				if(data.status == 0){
					alert("开票数据缓存成功！");
				}
            });
        });

        //批量更新
		$('#export').click(function(){
            //选择范围
            var year = $('#year').val();
            var month = $('#month').val();
			if(!$.isNumeric(year) || !$.isNumeric(month)){
				alert("请选择需要导出数据的年份和月份！");
				return;
			}
            $.post("/report/region_indicator_progress/export", {
                '_token': '{{ csrf_token() }}',
                'year': year,
                'month': month,
            }, function(data){
				if(data.status == 0){
					alert("导出数据成功，请至目录[/storage/app/export]下查询！");
				}
            });
        });
	});
</script>
@endsection